﻿using System;
using System.Collections.Generic;

namespace _1528_shuffle_string
{
    class Program
    {
        static void Main (string[] args)
        {
            string s = "codeleet";
            int[] indeces = { 4, 5, 6, 7, 0, 2, 1, 3 };
            Console.WriteLine (RestoreString2 (s, indeces));
        }

        public static string RestoreString (string s, int[] indices)
        {
            string str = "";
            for (int i = 0;i < indices.Length;i++)
            {
                for (int j = 0;j < indices.Length;j++)
                {
                    str += indices[j] == i ? s[j].ToString(): "";
                }
            }

            return str;
        }

        public static string RestoreString2 (string s, int[] indices)
        {
            Dictionary<int, int> indice = new Dictionary<int, int> ();
            for (int i = 0;i < indices.Length;i++)
            {
                indice.Add (indices[i], i);
            }
            
            string str = "";
            for (int i = 0;i < indices.Length;i++)
            {
                str += s[indice[i]];
            }

            return str;
        }
    }
}
